package com.线程和进程;

import java.io.IOException;

public class MyThreadDemo {
    public static void main(String[] args) {
        /*设置线程名1*/
//        MyThread mt1 = new MyThread();
//        MyThread mt2 = new MyThread();
//        mt1.setName("高铁");
//        mt2.setName("飞机");

        /*设置线程名2*/
        //Thread(String name)，这个是Thread类的带参构造方法，若要使用需要自己来其子类中创建一个带参
        //构造方法，并用super()进行继承。
        MyThread mt0 = new MyThread("步行");
        mt0.start();
        try {
            mt0.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        MyThread mt1 = new MyThread("飞机");
        MyThread mt2 = new MyThread("高铁");
        MyThread mt3 = new MyThread("火车");

        /*static Thread currentThread()返回对当前正在执行的线程对象的引用*/
        System.out.println(Thread.currentThread().getName()); //main

        /*线程优先级*/
        System.out.println(Thread.MAX_PRIORITY); //10
        System.out.println(Thread.MIN_PRIORITY); //1
        System.out.println(Thread.NORM_PRIORITY); //5

        /*设置线程优先级*/
        mt1.setPriority(10);
        mt2.setPriority(7);
        mt3.setPriority(4);

        /*启动线程*/
        mt1.start();
        mt2.start();
        mt3.start();
    }
}

/*通过无参构造方法创造MyThread类对象，而子类无参构造方法会默认访问父类的构造方法*/
/*
private volatile String name;

public Thread() {
    this(null, null, "Thread-" + nextThreadNum(), 0);
}

public Thread(String name) {
    this(null, null, name, 0);
}

public Thread(ThreadGroup group, Runnable target, String name,
                  long stackSize) {
    this(group, target, name, stackSize, null, true);
}

private Thread(ThreadGroup g, Runnable target, String name,
                   long stackSize, AccessControlContext acc,
                   boolean inheritThreadLocals) {
    this.name = name;
}

private static int threadInitNumber; 静态值，默认从0开始
private static synchronized int nextThreadNum() {
    return threadInitNumber++;
}

public final String getName() {
    return name;
}

public final synchronized void setName(String name) {
    this.name = name;
}
*/